home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / DrawFile / h / GuiDrawFilePath < prev    next >
Text File  |  2003-02-14  |  6KB  |  150 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #ifndef GuiDrawFilePath_h
  39. #define GuiDrawFilePath_h
  40.  
  41. #include "GuiDrawFile.h"
  42.  
  43. class GuiDrawFilePathState
  44. {
  45.   public:
  46.     enum {OFF = -1};
  47.     GuiDrawFilePathState() : reserved(0) {reset();}
  48.     void reset();
  49.  
  50.     //**** fill methods ****
  51.     void         setFillColour(unsigned int colour=OFF)            {fillColour=colour;}
  52.     unsigned int getFillColour() const                             {return fillColour;}
  53.  
  54.     enum {NON_ZERO = (0<<6), EVEN_ODD = (1<<6)};
  55.     void setWindingRule(int rule=NON_ZERO)         {pathStyle= ((pathStyle &~ (1<<6)) | rule);}
  56.     int  getWindingRule() const                     {return pathStyle & (1<<6);}
  57.  
  58.  
  59.     //**** outline methods ****
  60.  
  61.     void         setOutlineColour(unsigned int colour=OFF)         {outlineColour=colour;}
  62.     unsigned int getOutlineColour() const                          {return outlineColour;}
  63.  
  64.     void         setOutlineWidth(size_t width=0)                   {outlineWidth=width;}
  65.     unsigned int getOutlineWidth() const                           {return outlineWidth;}
  66.  
  67.     void         setDashPattern(bool on=0)        {pathStyle = ((pathStyle &~ (1<<7)) | (on ? (1<<7):0));}
  68.     bool         isDashPattern() const            {return pathStyle & (1<<7);}
  69.  
  70.     //***** outline joins ****
  71.     enum 
  72.     {
  73.       JOIN_MITRED,
  74.       JOIN_ROUND,
  75.       JOIN_BEVELLED,
  76.       JOIN_MASK
  77.     };
  78.  
  79.     void setJoin(int n=JOIN_MITRED)      {pathStyle = (pathStyle &~ 3) | n;}
  80.     int  getJoin() const                 {return pathStyle & (3<<0);} 
  81.  
  82.     //***** outline caps *******
  83.     enum
  84.     {
  85.       CAP_BUTT,
  86.       CAP_ROUND,
  87.       CAP_SQUARE,
  88.       CAP_TRIANGLE
  89.     };
  90.  
  91.     void setEndCap(int n=CAP_BUTT)        {pathStyle= ((pathStyle &~ (3<<2)) | (n<<2));}
  92.     int  getEndCap() const                {return (pathStyle >> 2) & 3;}
  93.  
  94.     void setStartCap(int n=CAP_BUTT)      {pathStyle= ((pathStyle &~ (3<<4)) | (n<<4));}
  95.     int  getStartCap() const              {return (pathStyle >> 4) & 3;}
  96.  
  97.     void setCapWidth(size_t wid=0)        {capWidth=wid;}
  98.     int  getCapWidth() const              {return capWidth;}
  99.  
  100.     void setCapHeight(size_t ht=0)        {capHeight=ht;}
  101.     int  getCapHeight() const             {return capHeight;}
  102.  
  103.   private:
  104.     unsigned int  fillColour;
  105.     unsigned int  outlineColour;
  106.     size_t        outlineWidth;
  107.     unsigned char pathStyle;
  108.     unsigned char reserved;
  109.     unsigned char capWidth;
  110.     unsigned char capHeight;
  111. };
  112.  
  113. class GuiDrawFilePath
  114. {
  115.   public:
  116.     enum {OBJECT_ID = 2};
  117.  
  118.     GuiDrawFilePath(GuiDrawFile&);
  119.     ~GuiDrawFilePath();
  120.  
  121.     void point(int x,int y)  {
  122.                                drawfile.put(x);drawfile.put(y);
  123.                                if (x<ob.bounds.xmin) ob.bounds.xmin=x;
  124.                                if (x>ob.bounds.xmax) ob.bounds.xmax=x;
  125.                                if (y<ob.bounds.ymin) ob.bounds.ymin=y;
  126.                                if (y>ob.bounds.ymax) ob.bounds.ymax=y;
  127.                              }
  128.     void start();
  129.     void end(const GuiDrawFilePathState&,bool clip=0);
  130.  
  131.     // if there is a dash pattern dashPattern must follow start and state must have patten flag set
  132.     void dashPattern(int start_distance_in_dash,int number_of_elements)
  133.                                    {
  134.                                      drawfile.put(start_distance_in_dash);
  135.                                      drawfile.put(number_of_elements);
  136.                                    }
  137.     void dashElement(size_t size)  {drawfile.put(size);}
  138.  
  139.     void moveTo()                  {drawfile.put(2);} // followed by 1 point - opens path
  140.     void closeSubPath()            {drawfile.put(5);} // followed by 0 points
  141.     void bezierTo()                {drawfile.put(6);} // followed by 3 points
  142.     void drawTo()                  {drawfile.put(8);} // followed by 1 point
  143.  
  144.   private:
  145.     GuiDrawFile&              drawfile;
  146.     GuiDrawFileGraphicsObject ob;
  147. };
  148.  
  149. #endif
  150.